<template>
  <d2-container class="page">
    <div class="page-form">
      <el-form :inline="true" :model="queryForm">
        <el-form-item label="微信号">
          <el-input v-model="queryForm.wxName" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="datetime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="page-table">
      <d2-crud
        :loading="loading"
        :columns="tableColumns"
        :data="tableData"
        :pagination="pagination"
        @pagination-current-change="pageChange"
      />
    </div>
  </d2-container>
</template>

<script>
  import { mapActions } from 'vuex'

  const tableColumns = [
    { title: '微信号', key: 'wxName' },
    { title: '微信昵称', key: 'wxNickname' },
    { title: '手机号', key: 'wxPhone' },
    { title: '创建时间', key: 'createTime' }
  ]
  export default {
    name: 'group',
    data () {
      return {
        loading: false,
        queryForm: {
          page: 1,
          limit: 10,
          wxName: '',
          startTime: '',
          endTime: ''
        },
        pagination: {
          currentPage: 1,
          pageSize: 10,
          total: 0
        },
        tableColumns,
        tableData: [],
        datetime: []
      }
    },
    mounted () {
      this.queryList()
    },
    methods: {
      ...mapActions('d2admin/sys.log', [
        'logList'
      ]),
      // 查询列表
      queryList () {
        this.loading = true
        this.logList(this.queryForm).then(res => {
          this.loading = false
          this.tableData = res.list
          this.pagination.total = res.totalCount
        }).catch(err => {
          this.loading = false
        })
      },
      // 其他用途调用
      queryHandle (page) {
        this.queryForm.page = page
        this.queryList()
      },
      // 切换分页
      pageChange (curr) {
        this.queryHandle(curr)
      },
      // 点击查询按钮
      onSubmit () {
        if (this.datetime[0]) {
          this.queryForm.startTime = this.$dateFormat('yyyyMMdd', this.datetime[0]) + '000000'
        }
        if (this.datetime[1]) {
          this.queryForm.endTime = this.$dateFormat('yyyyMMdd', this.datetime[1]) + '235959'
        }

        this.queryHandle(1)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .page {
    .page-form {
      border: 1px solid #eee;
      padding: 20px 20px 0;
    }
    .page-table {
      border: 1px solid #eee;
      padding: 20px;
      margin-top: 20px;
    }
  }
</style>
